package com.coolw.log4j2.mask.controller;

import com.alibaba.fastjson2.JSON;
import com.coolw.common.api.BaseResult;
import com.coolw.log4j2.mask.dto.UserDTO;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 日志-请求控制层
 *
 * @author coolw
 * @date 2024/4/19 17:00
 */
@Slf4j
@RequestMapping("/log")
@RestController
public class LogController {

    @GetMapping("/field")
    public BaseResult<Void> field() {
        log.info("userName:{},idCard:{},phone:{}", "赵子龙", "430623199010100050", "15000990001");
        return BaseResult.success();
    }

    @GetMapping("/user")
    public BaseResult<Void> user() {
        UserDTO userDTO = new UserDTO();
        userDTO.setUserName("赵子龙");
        userDTO.setIdCard("430623199010100050");
        userDTO.setPhone("15000990001");
        log.info("userDTO:{}", userDTO);
        return BaseResult.success();
    }

    @GetMapping("/map")
    public BaseResult<Void> map() {
        Map<String, String> map = Maps.newHashMap();
        map.put("name", "赵子龙");
        map.put("fjdkjfd", "王自强");
        map.put("idCard", "430623199010100050");
        map.put("phone", "15000990001");
        log.info("map:{}", map);
        return BaseResult.success();
    }

    @GetMapping("/json")
    public BaseResult<Void> json() {
        Map<String, String> map = Maps.newHashMap();
        map.put("name", "赵子龙");
        map.put("fjdkjfd", "王自强");
        map.put("idCard", "430623199010100050");
        map.put("phone", "15000990001");
        log.info("jsonStr:{}", JSON.toJSONString(map));
        return BaseResult.success();
    }
}

